from tortoise import Model, fields
from datetime import datetime
import uuid

class RoomType(Model):
    """房型模型"""
    id = fields.CharField(pk=True, max_length=32, default=lambda: uuid.uuid4().hex)
    hotel = fields.ForeignKeyField("models.Hotel", related_name="room_types", description="关联酒店")
    name = fields.CharField(max_length=100, description="房型名称")
    area = fields.CharField(max_length=20, null=True, description="面积")
    beds = fields.CharField(max_length=100, null=True, description="床型")
    capacity = fields.CharField(max_length=50, null=True, description="入住人数")
    features = fields.JSONField(default=list, description="特色描述")
    price = fields.FloatField(description="单价（元/晚）")
    original_price = fields.FloatField(null=True, description="原价")
    discount = fields.FloatField(null=True, description="优惠金额")
    images = fields.JSONField(default=list, description="图片列表")
    description = fields.TextField(null=True, description="详细描述")
    status = fields.IntField(default=1, description="状态：0下架/1上架")
    create_time = fields.DatetimeField(default=datetime.now)
    update_time = fields.DatetimeField(auto_now=True)

    class Meta:
        table = "room_type"
        description = "商家端-酒店房型信息"

    def __str__(self):
        return f"{self.name} ({self.price}元)"